﻿#ifndef CLIENT_H
#define CLIENT_H

#include <QObject>
#include <QTcpSocket>
#include <QHostAddress>
#include <QTimer>
class Client : public QObject
{
    Q_OBJECT

private:   
    QTimer *timer_heart;
    QTimer *timer_reConn;
    QTimer *timer_CAN_1;
    QTimer *timer_CAN_2;
    QTcpSocket *socket;
    QString ip;
    quint16 port;
    int count=0;
    bool isFirst=true;
    bool Count = false;
    int num = 0;
    QTimer m_Timer;
    QTimer *Heart_Timer;
    bool m_IsConnected = false;

public:
    explicit Client(QObject *parent = nullptr);

    void Toconnect(QString ip, quint16 port);
    void sendcan_data(QString data);
    void receiveData();
    void CANdataRec(QString da);
    void RS485dataRec(QString da);
    void RS485dataTem(QString da);
    void rectem1(QString da);
    void rectem2(QString da);
    void rectem3(QString da);
    void run();

    QString connectCount = "0";//TCP连接状态位
    QString rs485_1 = "000000000000000000000000";
    QString rs485_2 = "000000000000000000000000";
    QString rs485_3 = "000000000000000000000000";

    QString canData = "0000000000000000";

    //定位数据
    QString dw_data = "000000000000000000";

    //温度数据
    QString tem_data = "000000000000";

    QString tem1 = "000000000000";
    QString tem2 = "000000000000";
    QString tem3 = "000000000000";

public slots:
    void sendCANdata_1();//向CAN发送的数据  发送一

    void StopSend();

signals:
    void sig_tcp_shoSen(QString arr);
    void sig_rec_data(QByteArray arr);
    void CANCon(int ID,std::vector<int> vec);//CAN连接
    void sig_connect_suc();
    void sig_tcp_cloSuc();
    void sig_radar(QString bo);
    void sig_radar_dis(QString da);
    void cansend(QString da);

private slots:
    void doHeart();
    void isConnection();
    void isDisConnection();
    void reConnection();    
};

#endif // CLIENT_H
